package tasktracker.abstraction;

import java.io.File;

import org.slf4j.Logger;

public abstract class AbstractTaskTracker implements ITaskTracker {

	private ITaskTrackerContext context;
	protected ITaskDataStore dataStore;
	protected Logger logger;

	@Override
	public ITaskTrackerCharacteristics getCharacteristics() {
		return new TaskTrackerCharacteristics();
	}

	@Override
	public void registerContext(ITaskTrackerContext context) {
		this.context = context;
		this.dataStore = context.getTaskDataStore();
		this.logger = context.getLogger();
	}

	@Override
	public void destroy() {

	}

	@Override
	public void cancelTask(String guid) {
		throw new UnsupportedOperationException();
	}

	@Override
	public void restoreTask(TaskInfo task) throws Exception {
		throw new UnsupportedOperationException();
	}

	protected void reportStatus(String guid, int status, TaskResultInfo result) {
		context.reportStatus(guid, status, result);
	}

	protected void ensureInputPathExists(TaskInfo task) {
		if (task == null || task.getInputPath() == null)
			return;
		File folder = new File(task.getInputPath()).getAbsoluteFile();
		folder.mkdirs();
	}

	protected void ensureOutputPathExists(TaskInfo task) {
		if (task == null || task.getOutputPath() == null)
			return;
		File folder = new File(task.getOutputPath()).getAbsoluteFile();
		folder.mkdirs();
	}
}
